/**
 * Add at 2018年3月1日
 * 
 * 按顺序执行
 * 
 * 1) https://www.cnblogs.com/ys-ys/p/5208308.html
 *      + 如何定义"静态属性",参考上文
 * 
 * === 开发日志 ===
 * 1) 写不出来,虽然在参考了"EventProxy"后有一些思路,但是,怎样处理参数`callback.apply(this, args)`呢?
 *      + 另外时间有限,我不能在这上面花费太多时间!
 */

interface iFuncObj {
    key : string;
    func : any;
}

class ExecuteInTurn {
    static instanceCount:number = 0;
    static turn:number = 1;
    static arrExeFunc:any[] = [];
    private _callbacks:any = {};
    constructor(){
        ExecuteInTurn.instanceCount++;
    }
    public reg(func:any, delay?:number){
        let key: string = `Turn_${ExecuteInTurn.turn++}`;
        if(delay){
            this._callbacks[key] = function(){};
            ExecuteInTurn.arrExeFunc.push(function(){
                setTimeout(func, delay);
            });
        }else{
            ExecuteInTurn.arrExeFunc.push(func);
        }
    }
    public sayHello(){
        let both = 3;
        console.log(`== both: ${both} ==`);
        while(both--){
            let start = both ? 1 : 0;
            console.log(`both: ${both}, start: ${start}`);
        }
    }
}

let eit = new ExecuteInTurn();

eit.sayHello();




